package me.xingyannian.hope.rest;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import me.xingyannian.hope.entity.Menu;
import me.xingyannian.hope.service.MenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/menu")
public class MenuController {
    private MenuService menuService;

    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }

    @GetMapping("/{loginId}")
    @SaCheckLogin
    public SaResult getMenuByLoginId(@PathVariable String loginId){
        var currentLoginId = StpUtil.getLoginId();
        if (loginId.equals(currentLoginId)){
            return SaResult.data(this.menuService.getMenusByLoginId(loginId));
        }else {
            return SaResult.error("权限不足:当前账号未登录");
        }
    }

    @GetMapping("/token")
    @SaCheckLogin
    public SaResult getMenuByToken(){
        var currentLoginId = StpUtil.getLoginId();
        return SaResult.data(this.menuService.getMenusByLoginId(currentLoginId.toString()));
    }

}
